package com.tanguy.user.ui.trip.activity.choice

import android.app.Activity
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.tanguy.user.Const
import com.tanguy.user.R
import com.tanguy.user.base.ImmersionTitleActivity
import com.tanguy.user.bean.station.CityBean
import com.tanguy.user.net.http.HttpManager
import com.tanguy.user.ui.trip.activity.adapter.CityServiceAdapter
import com.tanguy.user.utlis.extend.requestSucceed
import com.tanguy.user.utlis.extend.setText
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/11/21 0021 16:59
 *  选择城市
 */
class ChoiceCityActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_choice_city
    val data = ArrayList<CityBean>()
    private val cityServiceAdapter = CityServiceAdapter(data)
    override fun initView() {
        super.initView()
        title = "切换城市"
        find<RecyclerView>(R.id.rv_content).apply {
            layoutManager = LinearLayoutManager(this@ChoiceCityActivity)
            adapter = cityServiceAdapter
        }
        setText(R.id.tv_my, "当前城市: ${intent.getStringExtra(Const.IntentCode.CITY_NAME)}")
    }

    override fun initEvent() {
        super.initEvent()
        cityServiceAdapter.setOnItemClick {
            _, _, data ->
            setResult(Activity.RESULT_OK, Intent().putExtra(Const.IntentCode.CITY_BEAN, data))
            finish()

        }
    }

    override fun initData() {
        super.initData()
        HttpManager.destination()
                .requestSucceed(this) {
                    val list = it.list
                    cityServiceAdapter.setNewData(list)
                }
    }
}